package com.greenold.service.controller;

import com.greenold.common.core.domain.AjaxResult;
import com.greenold.service.domain.dto.NurseDto;
import com.greenold.service.domain.vo.NurseNameVO;
import com.greenold.service.domain.vo.RoomVO;
import com.greenold.service.service.IRoomBedService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author YueYang
 * Created on 2025/10/15 14:23
 * @version 1.0
 */
@RestController
@RequestMapping("/service/manage")
public class RoomBedController {
    @Autowired
    private IRoomBedService roomBedService;

    /**
     * 查询当前楼层的所有房间列表
     *
     * @param floorId 楼层id
     * @return 返回响应集合
     */
    // @PreAuthorize("@ss.hasPermi('service:manage:list')")
    @GetMapping("/{floorId}")
    public AjaxResult queryRoomListByFloorId(@PathVariable Long floorId) {
        List<RoomVO> roomVOList = roomBedService.queryList(floorId);
        if (roomVOList != null) {
            return AjaxResult.success("查询成功", roomVOList);
        }
        return AjaxResult.error("查询失败");
    }

    /**
     * 查询所有楼层id
     *
     * @return 返回楼层id对应的集合
     */
   // @PreAuthorize("@ss.hasPermi('service:manage:floorIdList')")
    @GetMapping()
    public AjaxResult queryFloorIdList() {
        List<Long> ids = roomBedService.queryIdList();
        if (ids != null) {
            return AjaxResult.success("查询成功", ids);
        }
        return AjaxResult.error("查询失败");
    }

    /**
     * 获取所有的护理员信息，用于前端展示
     *
     * @return 返回所有的护理员信息
     */
    @GetMapping("/nurses")
   // @PreAuthorize("@ss.hasPermi('service:manage:nurses')")
    public AjaxResult queryNursesByBedId() {
        List<NurseNameVO> nurseNameVOList = roomBedService.queryNurses();
        if (nurseNameVOList != null) {
            return AjaxResult.success("查询成功", nurseNameVOList);
        }
        return AjaxResult.error("查询失败");
    }

    /**
     * 更新护理员绑定关系
     *
     * @param nurseDto 包含床位ID列表和护理员ID列表的数据传输对象
     * @return 返回操作结果
     */
    @PutMapping("/nurses")
    //@PreAuthorize("@ss.hasPermi('service:manage:nurses')")
    public AjaxResult updateNurseBinding(@RequestBody NurseDto nurseDto) {
        int result = roomBedService.updateNurseBinding(nurseDto);
        if (result > 0) {
            return AjaxResult.success("护理员绑定更新成功");
        } else {
            return AjaxResult.error("护理员绑定更新失败");
        }

    }

}
